<!---use this cfc with a component to create tag clouds or pull up related content--->
<cfcomponent>
<cffunction name="toptags" access="public" returntype="query" hint="returns a query of the most popular tags">
  <cfargument name="tag_group" type="string" required="no" default="blog">
  <cfargument name="maxtags" type="numeric" required="no" default="18">
  <cfquery name="qtags" datasource="#request.dsn#" maxrows="#maxtags#">
            SELECT tag,COUNT(tag) AS tagCount
            FROM core_tags
            WHERE tag_group = <cfqueryparam value="#tag_group#" cfsqltype="cf_sql_varchar">
            GROUP BY tag
            HAVING COUNT(tag) > 0
            ORDER BY tagCount DESC,
            tag
            </cfquery>
  <cfreturn qtags>
</cffunction>
<cffunction name="inserttags" access="public" output="Yes" returntype="void" hint="inserts tags for a tag cloud into the core_tags table">
  <cfargument name="tag_group" type="string" required="no" default="blog">
  <cfargument name="recid" type="numeric" required="yes" default="0">
  <cfargument name="tags" type="string" required="yes" default="" hint="comma delimited list of tags to insert for this recid">
  <cfquery name="qdeleteoldtags" datasource="#request.dsn#">
            DELETE FROM core_tags
            WHERE tag_group = <cfqueryparam value="#tag_group#" cfsqltype="cf_sql_varchar">
            AND recid = <cfqueryparam value="#recid#" cfsqltype="cf_sql_integer">
            </cfquery>
  <cfloop list="#tags#" index="t" delimiters=",">
  <cfif len(trim(t)) GT 0 AND len(trim(t)) LT 11>
    <cfquery name="qinserttag" datasource="#request.dsn#">
                    INSERT INTO core_tags
                    (tag, tag_group, recid)
                    VALUES
                    ('#t#', '#tag_group#', #recid#)
                    </cfquery>
  </cfif>
  </cfloop>
</cffunction>
<cffunction name="getcontent" access="public" returntype="query" hint="retrieves tagged content in the form a query">
  <cfargument name="tag" type="string" required="yes" default="" hint="tag to query">
  <cfargument name="jointable" type="string" required="yes" default="" hint="table to join to the core_tags table on recid">
  <cfargument name="idcol" type="string" required="yes" default="" hint="column name of the id field in your table that you are joining">
  <cfargument name="maxrows" type="numeric" required="no" default="6" hint="maximum number of records to obtain">
  <cfquery name="qcontent" datasource="#request.dsn#" maxrows="#maxrows#">
            SELECT * FROM core_tags JOIN #jointable# ON #jointable#.#idcol# = core_tags.recid
            WHERE tag = <cfqueryparam value="#tag#" cfsqltype="cf_sql_varchar">
            AND tag_group = <cfqueryparam value="#tag_group#" cfsqltype="cf_sql_varchar">
            </cfquery>
  <cfreturn qcontent>
</cffunction>
</cfcomponent>